package com.sixkey.model.response;

/**
 * ClassName: ResponseInfo
 * Package: com.sixkey.model.response
 * Description:
 *
 * @Author: @WeiXueShi
 * @Create: 2023/8/15 - 20:54
 * @Version: v1.0
 */

import lombok.Data;

/**
 * 响应类
 */
@Data
public class ResponseInfo<T> {
    /**
     * 状态码
     */
    protected int code;

    /**
     * 响应信息
     */
    protected String message;

    /**
     * 返回数据
     */
    private T data;

    public static <T> ResponseInfo<T> success() {
        return new ResponseInfo<>();
    }

    public static <T> ResponseInfo<T> success(T data) {
        return new ResponseInfo<>(data);
    }

    public static <T> ResponseInfo<T> fail(String message) {
        return (ResponseInfo<T>) new ResponseInfo<>(ResultEnum.FAILED.getCode(),message);
    }

    public ResponseInfo() {
        this.code = ResultEnum.SUCCESS.getCode();
        this.message = ResultEnum.SUCCESS.getMessage();
    }

    public ResponseInfo(ResultEnum statusEnums) {
        this.code = statusEnums.getCode();
        this.message = statusEnums.getMessage();
    }

    /**
     * 若没有数据返回，可以人为指定状态码和提示信息
     */
    public ResponseInfo(int code, String msg) {
        this.code = code;
        this.message = msg;
    }

    /**
     * 有数据返回时，状态码为200，默认提示信息为“操作成功！”
     */
    public ResponseInfo(T data) {
        this.data = data;
        this.code = ResultEnum.SUCCESS.getCode();
        this.message = ResultEnum.SUCCESS.getMessage();
    }

    /**
     * 有数据返回，状态码为 200，人为指定提示信息
     */
    public ResponseInfo(T data, String msg) {
        this.data = data;
        this.code = ResultEnum.SUCCESS.getCode();
        this.message = msg;
    }
}
